package middle;

import java.util.Arrays;

public class hua20 {
    public static void main(String[] args) {
        int[] breakpoints = {2,3000,5000,8000,9990};
        System.out.println(batchCalculation(5, 1, breakpoints));
    }


    private static int batchCalculation(int nCount, int mCount, int[] nums) {
        if(mCount>=nCount){
            return 10000;
        }
        // TODO 在此补充你的代码
        int firstInterval = nums[0] - 1;
        int[] intervals=new int[nCount+1];
        intervals[0]=firstInterval;
        for (int i = 1; i < nums.length; i++) {
            int interval = nums[i] - nums[i - 1] - 1;
            if (interval > 0) {
                intervals[i]=interval;
            }
        }
        int lastInterval = 10000 - nums[nums.length - 1];
        intervals[nCount]=lastInterval;
        for(int i:intervals){
            System.out.println(i);
        }

        int len=0;

        int curresult=0;
        for(int i=0;i<mCount+1;i++){
            curresult+=intervals[i];
        }
        int result=curresult;
        for(int i=mCount+1;i<intervals.length;i++){
            curresult=curresult-intervals[i-mCount-1]+intervals[i];
            result=Math.max(result,curresult);
        }
        return result+mCount;

    }
}
